/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.worldwizards;

import java.awt.BorderLayout;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JDialog;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/**
 *
 * @author Jeff Kesselman
 */
class InfoPanel extends JDialog {

    JEditorPane infoPane = new JEditorPane();

    public InfoPanel(JFrame appFrame) {
        super(appFrame);

        this.setTitle("Chart Display");
        this.setLocation(appFrame.getX() + (appFrame.getWidth() / 2), appFrame.getY() + (appFrame.getHeight() / 2));
        setLayout(new BorderLayout());
        String localDir = System.getProperty("user.dir");
        File chartsDir = new File(localDir+"/info");
        String[] chartNames = chartsDir.list();
        final JList nameList = new JList(chartNames);
        nameList.addListSelectionListener(new ListSelectionListener() {

            public void valueChanged(ListSelectionEvent e) {
                setChart(nameList.getSelectedValue());
            }
        });
        //infoPane = new JEditorPane(new File("info/dafault.html").toURI().toURL());
        add(new JScrollPane(nameList), BorderLayout.WEST);
        add(new JScrollPane(infoPane), BorderLayout.CENTER);
        pack();

    }

    private void setChart(Object selectedValue) {
         String localDir = System.getProperty("user.dir");
        String path = localDir+"/info/"+(String)selectedValue;
        try {
            infoPane.setPage(new File(path).toURI().toURL());
            pack();
        } catch (IOException ex) {
            Logger.getLogger(InfoPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
